package com.dinim.object;

import com.dinim.matrix.twodimensional.IPoint2D;

public class Star2D extends Object2D{

    public Star2D(double x, double y, double width, double height, int tines) {
        super(createPoints(x, y, width, height, tines), createConnectoins(tines));
    }

//    private static int[] createConnectoins(int tines){
//        int[] connections = new int[2 * tines];
//        for(int i = 0; i < connections.length; i++){
//            connections[i] = i;
//        }
//        return connections;
//    }
//    
//    private static IPoint2D[] createPoints(double x, double y, double width, double height,
//                                           int tines){
//        Point2D[] points = new Point2D[tines * 2];
//        double halfWidth = width / 2;
//        double halfHeight = height / 2;
//        double midX = x + halfWidth;
//        double midY = y + halfHeight;
//        boolean outer = true;
//        for(int i = 0; i < 2 * tines; i++){
//            if(outer){
//                double px = midX + Math.cos(Math.toRadians(i * (360 / (tines * 2)))) * halfWidth;
//                double py = midY + Math.sin(Math.toRadians(i * (360 / (tines * 2)))) * halfHeight;
//                points[i] = new Point2D(px, py);
//            } else {
//                double px = midX + Math.cos(Math.toRadians(i * (360 / (tines * 2)))) * halfWidth/2;
//                double py = midY + Math.sin(Math.toRadians(i * (360 / (tines * 2)))) * halfHeight/2;
//                points[i] = new Point2D(px, py);
//            }
//            outer = !outer;
//        }
//        return points;
//    }
    
    private static int[] createConnectoins(int tines){
        int[] connections = new int[tines];
        for(int i = 0; i < connections.length; i++){
            connections[i] = i;
        }
        return connections;
    }
    
    private static IPoint2D[] createPoints(double x, double y, double width, double height,
                                           int tines){
        Point2D[] points = new Point2D[tines];
        double halfWidth = width / 2;
        double halfHeight = height / 2;
        double midX = x + halfWidth;
        double midY = y + halfHeight;
        boolean outer = true;
        for(int i = 0; i < tines; i++){
            if(true){
                double px = midX + Math.cos(Math.toRadians(i * (360 / (tines)))) * halfWidth;
                double py = midY + Math.sin(Math.toRadians(i * (360 / (tines)))) * halfHeight;
                points[i] = new Point2D(px, py);
            }
            outer = !outer;
        }
        return points;
    }
    
}
